package very.util.rpc

import org.json4s.JValue
import play.api.mvc.{ Action, AnyContent, Request }

trait WithRPCServer[CommonEntity[_] <: Request[_]] {
  implicit protected def rpcHelper: RpcCtrHelper[CommonEntity]

  protected def rpcAct[A, B](fn: Request[JValue] => Either[A, B]): Action[JValue] = rpcHelper.rpcAct(fn)

  protected def rpcAuthAct[A, B](fn: CommonEntity[JValue] => Either[A, B]): Action[JValue] = rpcHelper.rpcAuthAct(fn)

  protected def rpcGAct[A, B](fn: Request[AnyContent] => Either[A, B]): Action[AnyContent] = rpcHelper.rpcGAct(fn)

  protected def rpcAuthGAct[A, B](fn: CommonEntity[AnyContent] => Either[A, B]): Action[AnyContent] =
    rpcHelper.rpcAuthGAct(fn)
}
